﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Shell;

namespace VoiceRepeater
{
    public partial class FileBrowserPage : PhoneApplicationPage
    {

        public class ListData
        {
            public string Icon { get; set; }

            public string SongName { get; set; }
        }

        private SongCollection songs;
        public FileBrowserPage()
        {
            InitializeComponent();

            LoadFile();
        }

        private void LoadFile()
        {

            PhoneApplicationService.Current.State["selectSongs"] = null;

            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

            //string[] folders = iso.GetDirectoryNames();

            

            //string[] files = iso.GetFileNames();

            //List<string> total = folders.ToList();
            //total.AddRange(files.ToList());
            

            MediaLibrary mediaLib = new MediaLibrary();

            this.songs = mediaLib.Songs;
            List<string>  total = (from song in songs
                    select song.Name).ToList();
            listBoxFiles.ItemsSource = total;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            List<string> selectSongs = listBoxFiles.SelectedItems.Cast<string>().ToList();

            var songList = (from song in songs
                           where selectSongs.Contains(song.Name)
                            select song).ToList();

            PhoneApplicationService.Current.State["selectSongs"] = songList;
            NavigationService.Navigate(new Uri("/PlayListPage.xaml", UriKind.Relative));
        }

       
    }
}